class PropertyAttribute < ActiveRecord::Base
    set_table_name :product_property_attributes

    acts_as_nested_set :dependent => :destroy, :scope => :property_id

    belongs_to :property, :touch => true

    scope :group_by_presentation, :group => "presentation"
    
    #has_one :explanation_note, :dependent => :destroy, :as => :explanation
    has_one :property_value

    has_one  :property_enumerable,  :as => :enumerable
    has_one  :property_enum_group,  :through => :property_enumerable
    has_many :property_enum_values, :through => :property_enum_group
    
    validates :presentation, :presence => true, :length => {:maximum => 35}

    accepts_nested_attributes_for :property_value, :allow_destroy => true#, :reject_if => proc {|attr| attr['value'].blank?}

    delegate :value, :presentation, :to => :property_value, :prefix => true

    attr_accessor :node_parent_id, :node_next_id, :node_prev_id, :node_id

    alias new_property_value property_value
    def property_value
      new_property_value || build_property_value
    end

    def is_select?
      self.value_type == 'select'
    end
end
